#ifndef CMATRIX4X4_H
#define CMATRIX4x4_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.

*/

#include <iostream>
#include <math.h>

//4x4 square matrix. it is primarily intended to be used in the generation of shadow maps.
class CMatrix4x4
{
public:

    CMatrix4x4(); //empty constructor
    CMatrix4x4(float *raw_data); //constructor. vector components are initialised with x, y, z
    CMatrix4x4(const CMatrix4x4 &source); //copy constructor
    ~CMatrix4x4(); //deconstructor

    float& operator() (const unsigned short i, const unsigned short j); //() overload. outputs mData[i + 4*j]. i and j must be between 0 and 3.
    CMatrix4x4 operator+ (CMatrix4x4 matrix); //+ overload, element-wise sum of 2 matrices
    CMatrix4x4 operator+ (const float scalar); //+ overload, sum of matrix and scalar constant
    CMatrix4x4 operator- (CMatrix4x4 matrix); //- overload, element-wise subtraction of 2 matrices
    CMatrix4x4 operator- (const float scalar); //- overload, subtraction of scalar constant
    CMatrix4x4 operator* (CMatrix4x4 matrix); //* overload: matrix (rowsxcolumns) multiplication
    CMatrix4x4 operator* (const float scalar); //* overload: multiplication by a scalr value
    CMatrix4x4& operator= (CMatrix4x4 matrix); //= overload
    bool operator== (const CMatrix4x4 matrix);//== overload

    void LoadIdentity();
    CMatrix4x4 Transpose();
    float* GetRow(const unsigned short i);
    float* Data();

    //non-member operators
    friend std::ostream & operator << (std::ostream &out, CMatrix4x4 &mat);

private:

    float mData[16];

};


#endif // CMATRIX4x4_H
